// pages/ucenter/rechargeRecord/rechargeRecord.js
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');

var app = getApp();
Page({
    data: {
        rechargeList: [],
        page: 1,
        limit: 10,
        totalPages: 1
    },
    onLoad: function (options) {
        // 页面初始化 options为页面跳转所带来的参数
        this.getRechargeList();
    },
    onReady: function () {
        // 页面渲染完成
    },
    onShow: function () {
        // 页面显示
        this.getRechargeList();
    },
    getRechargeList() {
        wx.showLoading({
            title: '加载中...',
        });
        let that = this;
        util.request(api.RechargeRecordList, {
            page: that.data.page,
            limit: that.data.limit
        }
        ).then(function (res) {
            if (res.errno === 0) {
                let list = res.data.list;
                that.setData({
                    rechargeList: that.data.rechargeList.concat(list),
                    totalPages: res.data.pages
                });
            }
        });
        wx.hideLoading();
    },
    onHide: function () {
        // 页面隐藏
    },
    onUnload: function () {
        // 页面关闭
    },
    onReachBottom() {
        if (this.data.totalPages > this.data.page) {
            this.setData({
                page: this.data.page + 1
            });
            this.getRechargeList();
        } else {
            wx.showToast({
                title: '没有更多充值记录了',
                icon: 'none',
                duration: 2000
            });
            return false;
        }
    },
})